

function getYzm() {
  setTimeout(async () => {
    let img = document.querySelector("#yhmimg");
    if (img && img.src) {
      let canvas = document.getElementById('canvasYzm');
      if (!canvas) {
        canvas = document.createElement('canvas');
        canvas.id = 'canvasYzm'
        canvas.width = img.width;
        canvas.height = img.height;
      }
      let ctx = canvas.getContext('2d');
      ctx.clearRect(0, 0, img.width, img.height);
      ctx.drawImage(img, 0, 0, img.width, img.height);
      // var imageData = ctx.getImageData(0, 0, canvas.width , canvas.height );
      // var imageData_length = imageData.data.length / 4;
      // for (var i = 0; i < imageData_length; i++) {
      //   var red = imageData.data[i * 4];
      //   var green = imageData.data[i * 4 + 1];
      //   var blue = imageData.data[i * 4 + 2];
      //   var gray = 0.3 * red + 0.59 * green + 0.11 * blue;
      //   var new_black;
      //   if (gray > 180) {
      //       new_black = 255;
      //       // imageData.data[i * 4] = new_black;
      //       // imageData.data[i * 4 + 1] = new_black;
      //       // imageData.data[i * 4 + 2] = new_black;
      //   } else {
      //       new_black = 0;
      //       imageData.data[i * 4] = 255;
      //       imageData.data[i * 4 + 1] = 0;
      //       imageData.data[i * 4 + 2] = 0;
      //   }
      // }
      // ctx.putImageData(imageData, 0, 0);
      // document.querySelector("#yhmwrapper").appendChild(canvas);
      let imgSrc = img.src.split('?')[0];
      let ext = imgSrc.substring(imgSrc.lastIndexOf('.') + 1).toLowerCase();
      let dataUrl = canvas.toDataURL('images/' + ext);
      // console.log(dataUrl);
      // let dataUrl = '';
      // console.log(dataUrl);
      // let base64Image = await getBase64(img.src);
      window.postMessage(
        {
          event: "getYzmapi",
          data: {
            base64Image: dataUrl.split(',')[1],
            keyWord: '01',
            type: '1'
          },
        },
        "*"
      );
    }
  }, 3000);
}
function autoInputAccount({ companyInfo }) {
  if (!companyInfo) return false;
  let loginopen = $("#loginopen");
  if (loginopen.text().includes('登录') && !loginopen.attr('href')) {
    loginopen.click()
    companyInfo = companyInfo || {};
    $("#username").val(
      companyInfo.nationalTaxAccount ||
        companyInfo.nationalTaxId ||
        companyInfo.nationalTaxNo
    );
    $("#password").val(companyInfo.nationalTaxPass);
  }
}
export {autoInputAccount}
